package com.ruoyi.common.utils;

import java.util.regex.Pattern;

/**
 * @author KING
 * @date 2023-03-25 16:38
 * ruoyi
 */
public final class DataValidateUtil {
    private static final Pattern cnumber_1 = Pattern.compile("^\\d+$");
    private static final Pattern cnumber = Pattern.compile("[0-9]*");
    private static final Pattern cdate_1 = Pattern.compile("^\\d{4}-\\d{2}-\\d{2}$");
    private static final Pattern cphone_1 = Pattern.compile("^1[358]\\d{9}$");
    private static final Pattern cimg_1 = Pattern.compile(".*\\.(jpg|jpeg|png)", Pattern.CASE_INSENSITIVE);
    private static final Pattern cimg_2 = Pattern.compile(".*\\.(jpg|jpeg|png|gif)", Pattern.CASE_INSENSITIVE);
    private static final Pattern cimg_3 = Pattern.compile(".*\\.(jpg|jpeg|png|mp4|gif)", Pattern.CASE_INSENSITIVE);
    private static final Pattern cimg_4 = Pattern.compile(".*\\.(jpg|jpeg|png|mp4|mp3|M4V)", Pattern.CASE_INSENSITIVE);
    private static final Pattern cidcard_15 = Pattern.compile("^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$");
    private static final Pattern cidcard_18 = Pattern.compile("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$");
    private static final Pattern numberChain = Pattern.compile("(\\d+,)*\\d+");
    private static final Pattern cmoney = Pattern.compile("^\\d{1,10}(\\.\\d{1,2})?$");
    private static final Pattern caduio = Pattern.compile(".*\\.(mp3|wav|ogg)", Pattern.CASE_INSENSITIVE);
    private static final Pattern cimg_5 = Pattern.compile(".*\\.(mp4|mp3|M4V|gif)", Pattern.CASE_INSENSITIVE);

    /**
     * 验证字符串是否为yyyy-MM-dd格式日期（非严格验证）
     * @param s
     * @return
     */
    public static boolean UncheckedDate(String s)
    {
        return DataValidateUtil.cdate_1.matcher(s).matches();
    }

    /**
     * 验证手机号是否正确（非严格验证）
     * @param s
     * @return
     */
    public static boolean UncheckedPhone(String s)
    {
        return DataValidateUtil.cphone_1.matcher(s).matches();
    }

    /**
     * 验证图片是否为jpg或png格式
     * @param s
     * @return
     */
    public static boolean checkImg_JPG_PNG(String s)
    {
        return DataValidateUtil.cimg_2.matcher(s).matches();
    }
    /**
     * 验证图片是否为jpg或png或MP4格式
     * @param s
     * @return
     */
    public static boolean checkImg_JPG_PNG_MP4(String s)
    {
        return DataValidateUtil.cimg_3.matcher(s).matches();
    }
    /**
     * 验证图片是否为jpg或png、MP3或MP4格式
     * @param s
     * @return
     */
    public static boolean checkImg_JPG_PNG_MP4_MP3_M4V(String s)
    {
        return DataValidateUtil.cimg_4.matcher(s).matches();
    }

    /**
     * 验证图片是否为jpg、png或gif格式
     * @param s
     * @return
     */
    public static boolean checkImg_JPG_PNG_GIF(String s)
    {
        return DataValidateUtil.cimg_2.matcher(s).matches();
    }

    /**
     * 验证字符串是否为一个正整数
     * @param s
     * @return
     */
    public static boolean checkNumber1(String s)
    {
        return DataValidateUtil.cnumber_1.matcher(s).matches();
    }
    /**
     * 验证MP3或MP4格式
     * @param s
     * @return
     */
    public static boolean checkImg_MP4_MP3_M4V(String s)
    {
        return DataValidateUtil.cimg_5.matcher(s).matches();
    }
    /**
     * 验证字符串是否为数字
     * @param s
     * @return
     */
    public static boolean checkNumber(String s)
    {
        return DataValidateUtil.cnumber.matcher(s).matches();
    }
    /**
     * 验证身份证号（15位或18位）
     * @param s
     * @return
     */
    public static boolean checkIdcard(String s)
    {
        return DataValidateUtil.cidcard_18.matcher(s).matches() || DataValidateUtil.cidcard_15.matcher(s).matches();
    }

    /**
     * 验证数字链格式数据(格式：num1,num2,num3...)
     * @param s
     * @return
     */
    public static boolean checkNumberChain(String s) {
        return DataValidateUtil.numberChain.matcher(s).matches();
    }

    /**
     * 验证金额数据格式
     * @param s
     * @return
     */
    public static boolean checkMoney(String s) {
        return DataValidateUtil.cmoney.matcher(s).matches();
    }

    /**
     * 验证音频文件
     * @param s
     * @return
     */
    public static boolean checkAudio(String s) {
        return DataValidateUtil.caduio.matcher(s).matches();
    }
}
